<template>
  <el-container v-loading="loading">

    <el-row>
      <el-button
        icon="fa fa-fw fa-refresh"
        size="mini"
        type="info"
        @click="handleRefresh">
      </el-button>
    </el-row>

    <el-table
      @selection-change="handleSelectionChange"
      :data="tableData"
      tooltip-effect="dark"
      border
      :default-sort="{prop: 'date', order: 'descending'}"
      :row-class-name="tableRowClassName"
      size="small">
      <el-table-column
        prop="uname"
        label="用户姓名">
      </el-table-column>
<el-table-column
        prop="carnum"
        label="车牌号码">
      </el-table-column>
      <el-table-column
        prop="dname"
        label="代驾姓名">
      </el-table-column>

      <el-table-column
        prop="msg"
        label="留言"
        show-overflow-tooltip>
      </el-table-column>

      <el-table-column
        prop="create_time"
        label="创建时间"
        sortable>
        <template slot-scope="scope">
          <i class="fa fa-clock-o fa-fw"></i>
          <span style="margin-left: 10px">{{ scope.row.create_time }}</span>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.currentPage"
      :page-sizes="pagination.pageSizes"
      :page-size="pagination.pageSize"
      :total="pagination.total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

  </el-container>
</template>

<script>
  export default {
    mounted: function () {
      this.getData();
    },
    methods: {
      /**
       * 数据请求
       * */
      getData:function () {
        let _this = this;
        this.api.getFeedbackList({page: this.pagination.rows, paginate: this.pagination.pageSize}).then(function (res) {
          if (res.code == 1) {
            _this.tableData = res.data.data;
            _this.pagination.total = res.data.total;
            _this.loading = false;
          }
        }).catch(function (res) {
          throw new Error(res);
        });
      },
      /**
       * 分页数改变
       */
      handleSizeChange:function (pageSize) {
        this.pagination.pageSize = pageSize;
        this.getData();
      },
      /**
       * 当前页面改变
       * @param currentPage
       */
      handleCurrentChange:function (currentPage) {
        this.pagination.currentPage = currentPage;
        this.getData();
      },
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row'
        } else if (rowIndex === 3) {
          return 'success-row'
        }
        return ''
      },
      /**
       * 编辑单个
       * */
      handleEditItem(index, row) {
        this.$router.push({
          name: 'ClauseEditer',
          params: {
            id: row.id,
            methodType: this.constant.EDITORMETHOD
          }
        })
      },
      /**
       * 数据刷新
       */
      handleRefresh:function () {
        this.getData();
        this.$message({
          showClose: true,
          message: '刷新成功',
          type: 'success'
        });
      },
      /**
       * 表格选中状态记录
       * @param val
       */
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    },
    data() {
      return {
        loading: true,  // 页面加载
        tableData: [],
        multipleSelection:[],
        pagination:{
          total: 5,
          currentPage:1,
          pageSize: 10,
          pageSizes:[5,10,20,25,30,50,100],
        },
      }
    },
  }
</script>

<style scoped>
  .el-container {
    display: block;
    width: 98%;
    margin: 0 auto;
  }

  .el-table {
    width: 100% !important;
  }

  .el-row, .el-pagination {
    margin: 15px 0;
  }

  .el-pagination {
    text-align: center;
  }
</style>
